package com.yvtian.pu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.yvtian.pu.dao.PuApplyForMapper;
import com.yvtian.pu.pojo.PuApplyForEntity;
import com.yvtian.pu.pojo.PuOrderEntity;
import com.yvtian.pu.service.PuApplyForService;
import com.yvtian.utils.StringHelper;
import org.springframework.stereotype.Service;
import org.springframework.util.ObjectUtils;

/**
 * 申请采购单(pu_applyfor)表服务实现类
 *
 * @author long
 * @since 2024-06-24 10:26:28
 */
@Service("puApplyforService")
public class PuApplyforServiceImpl extends ServiceImpl<PuApplyForMapper, PuApplyForEntity> implements PuApplyForService {

    @Override
    public IPage<PuApplyForEntity> findByPage(Page<PuApplyForEntity> page, PuApplyForEntity puApplyforEntity) {
        LambdaQueryWrapper<PuApplyForEntity> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(PuApplyForEntity::getIsDel, 0);
        getQueryWrapper(puApplyforEntity, queryWrapper);
        return this.page(page, queryWrapper);
    }

    private void getQueryWrapper(PuApplyForEntity puApplyforEntity, LambdaQueryWrapper<PuApplyForEntity> queryWrapper) {
        if (StringHelper.isNotEmpty(puApplyforEntity.getCode())) {
            queryWrapper.like(PuApplyForEntity::getCode, puApplyforEntity.getCode());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getApplyUsername())) {
            queryWrapper.eq(PuApplyForEntity::getApplyUsername, puApplyforEntity.getApplyUsername());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getApplyAccount())) {
            queryWrapper.eq(PuApplyForEntity::getApplyAccount, puApplyforEntity.getApplyAccount());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getPuType())) {
            queryWrapper.eq(PuApplyForEntity::getPuType, puApplyforEntity.getPuType());
        }
        if (!ObjectUtils.isEmpty(puApplyforEntity.getAmount())) {
            queryWrapper.eq(PuApplyForEntity::getAmount, puApplyforEntity.getAmount());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getProjectCode())) {
            queryWrapper.eq(PuApplyForEntity::getProjectCode, puApplyforEntity.getProjectCode());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getProjectName())) {
            queryWrapper.eq(PuApplyForEntity::getProjectName, puApplyforEntity.getProjectName());
        }
        if (!ObjectUtils.isEmpty(puApplyforEntity.getStatus())) {
            queryWrapper.eq(PuApplyForEntity::getStatus, puApplyforEntity.getStatus());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getLimitTimeStr())) {
            String limitTimeStr = puApplyforEntity.getLimitTimeStr().trim();
            String[] split = limitTimeStr.split("~");
            queryWrapper.between(PuApplyForEntity::getLimitTime, split[0], split[1]);
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getCreateName())) {
            queryWrapper.like(PuApplyForEntity::getCreateName, puApplyforEntity.getCreateName());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getUpdateName())) {
            queryWrapper.like(PuApplyForEntity::getUpdateName, puApplyforEntity.getUpdateName());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getCreateUser())) {
            queryWrapper.like(PuApplyForEntity::getCreateUser, puApplyforEntity.getCreateUser());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getRemarks())) {
            queryWrapper.like(PuApplyForEntity::getRemarks, puApplyforEntity.getRemarks());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getCheckName())) {
            queryWrapper.like(PuApplyForEntity::getCheckName, puApplyforEntity.getCheckName());
        }
        if (StringHelper.isNotEmpty(puApplyforEntity.getCheckUser())) {
            queryWrapper.like(PuApplyForEntity::getCheckUser, puApplyforEntity.getCheckUser());
        }
    }
}

